﻿/**
 * Scene_Title
 * 
 * @version 2012.01.15
 * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
 */

// TODO: GAME MODE

#region XNA Libraries

using Microsoft.Xna.Framework.Input;
using System;

#endregion

#region SDK Libraries

using main.sdk.audio;
using main.sdk.display;
using main.sdk.display.object2d;
using main.sdk.input;
using main.sdk.scene;

#endregion

namespace main.src.scene
{

    public sealed class Scene_Option : Scene_Base
    {

        #region Instance Variables

        private Label[] Commands   = { new Label("Sound Background"), new Label("Sound Effect"), new Label("Level"), new Label("Exit") };
        private Sprite  Ball       = new Sprite("RSC/Picture/Ball");
        private Sprite  ArrowLeft  = new Sprite("RSC/Picture/ArrowLeft");
        private Sprite  ArrowRight = new Sprite("RSC/Picture/ArrowRight");
        private uint    Step       = 1;     //faltou explicar ao que se refere(Marcelo)
        private int     Index      = 0;
        private int     Direction  = 0;
        private byte    BGM        = 25;
        private byte    SE         = 25;
        private int     Distance   = 74;
        private byte    SoundLevel = 10;
        private Label   DSound;
        private int     Definition = 0;     //faltou explicar ao que se refere(Marcelo)
                   
        #endregion

        #region Instance Methods

        public override void Start()
        {

            #region Ball
            Ball.OX = Ball.Width / 2;
            Ball.OY = Ball.Height / 2;
            Ball.XO = 32;
            Ball.YO = Program.Height - Commands.Length * Distance - 16;
            Ball.Scale.X = 8;
            Ball.Scale.Y = 8;
            Ball.Visible = false;
            #endregion

            #region Commands
            for (uint i = 0; i < Commands.Length; i++)
            {
                Commands[i].X = Ball.X + (i == 0 ? 32 : 0);
                Commands[i].Y = Ball.YO + i * Distance;
                Commands[i].Alpha = 0;
                Commands[i].Outline = true;
                Commands[i].OutlineSize = 2;
            }
            #endregion     
            ArrowRight.Visible = false;
            ArrowLeft.Visible = false;
        }

        public override void Update()
        {

            switch (Step)
            {
                #region Ball & Commands
                case 1:
                    Ball.Visible  = true;
                    foreach (Label text in Commands)
                        text.Alpha += 50;
                    Ball.Scale.X -= 0.5f;
                    Ball.Scale.Y -= 0.5f;                    
                    if (Ball.Scale.X == 1)
                        Step = 2;
                    

                    break;
                #endregion

                #region Commands
                case 2:                    
                    
                    Ball.Degrees += 8;
                    Ball.Degrees %= 360;
                    if (Input.Trigger(Keys.Down))
                    {
                        Index++;
                        if (Index % Commands.Length == 0)
                        {
                            Index = 0;
                            Ball.YO -= Distance * (Commands.Length - 1);
                        }
                        else
                            Ball.YO += Distance;
                    }
                    if (Input.Trigger(Keys.Up))
                    {
                        Index--;
                        if (Index < 0)
                        {
                            Index = Commands.Length - 1;
                            Ball.YO += Distance * Index;
                        }
                        else
                            Ball.YO -= Distance;
                    }
                    for (uint i = 0; i < Commands.Length; i++)
                        Commands[i].X = Ball.X + (i == Index ? 32 : 0);
                    
                    if (Input.Press(Keys.Left))
                    {
                        Definition = 2;
                        Direction = 0;
                        Step = 3;
                    }
                    if (Input.Press(Keys.Right))
                    {
                        Definition = 1;
                        Direction = 0;
                        Step = 3;
                    }

                    break;
                #endregion

                #region Exit
                case 3:
                   
                        switch (Index)
                        {
                            case 0:
                                switch (Direction)
                                {
                                    case 0:

                                        ArrowRight.X = 120 + 48;
                                        ArrowRight.Y = 490;
                                        ArrowRight.Visible = true;                                                          
                                        ArrowLeft.X = 120 - 32;
                                        ArrowLeft.Y = 490;
                                        ArrowLeft.Visible = true;

                                        Direction = Definition;
                                                                                
                                    break;

                                    case 1:
                                    
                                        BGM += SoundLevel;
                                        if (BGM > 100)
                                            BGM = 100;
                                        if (DSound != null)
                                            DSound.Dispose();
                                        DSound = new Label(BGM.ToString());
                                        DSound.X = 120;
                                        DSound.Y = 490;
                                                                                               
                                        Audio.PlayBGM("RSC/Audio/Title",BGM);
                                        Step = 2;

                                    break;

                                    case 2:
                                    
                                        BGM -= SoundLevel;
                                        if (BGM > 100)
                                            BGM = 0;
                                        if (DSound != null)
                                            DSound.Dispose();
                                        DSound = new Label(BGM.ToString());
                                        DSound.X = 120;
                                        DSound.Y = 490;

                                        Audio.PlayBGM("RSC/Audio/Title",BGM);
                                        Step = 2;

                                    break;
                                }

                                break;

                            case 1:
                                switch (Direction)
                                {
                                    case 1:

                                        SE += SoundLevel;
                                        Audio.PlayBGM("RSC/Audio/Title",SE);
                                    break;
                                    case 2:
                                        SE -= SoundLevel;
                                        Audio.PlayBGM("RSC/Audio/Title",SE);                                        
                                    break;
                                }
                                Step = 2;
                                break;
                            case 2:
                                //Level
                                
                                break;
                            case 3:
                                Console.WriteLine("ok");

                                    Scene.Set(new Scene_Title());
                            break;
                            
                        }
                    break;
                #endregion
            }
        }

        public override void Terminate()
        {
            Ball.Dispose();
            ArrowLeft.Dispose();
            ArrowRight.Dispose();
        }

        #endregion

    }

}